/**
 * 
 */
package interview.preparation;

/**
 * @author sachintakkar
 * 
 */
public class Fibonacci {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		fiboIterative(6);

		System.out.println("Fib Sum " + fib(5));
	}

	public static int fib(int f) {

		if (f == 1 || f == 0)
			return f;
		return fib(f - 1) + fib(f - 2);
	}

	public static int sumFibo(int cnt, int n1, int n2, int sum) {
		sum += n1;
		if (cnt == 1) {
			return sum;
		} else {
			return sumFibo(--cnt, n2, (n1 + n2), sum);
		}
	}

	public static void fiboIterative(int n) {
		System.out.println("Fibo");

		int x = 0, y = 1, z;
		System.out.println(x + " ");
		System.out.println(y + " ");

		for (int i = 0; i < n - 2; i++) {
			z = x + y;
			System.out.println(z + " ");
			x = y;
			y = z;
		}
	}
}

// 0 1 1 2 3 5 8


// 6 

